﻿using AutoMapper;

using EmployeeCard.Model.Models;
using EmployeeCard.Model.ViewModels;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EmployeeCard.Extensions.AutoMapper
{
    public class CustomProfile : Profile
    {
        /// <summary>
        /// 配置构造函数，用来创建关系映射
        /// </summary>
        public CustomProfile()
        {
            CreateMap<BlogArticle, BlogViewModels>();
            #region 复杂深拷贝映射
            //属性名不一样
            CreateMap<Student, StudentViewModel>()
                .ForMember(x => x.ProvinceName, y => y.MapFrom(s => s.Province));//指定目标对象的ProvinceName属性应该从源对象的Province属性映射而来

            //含子类得复杂类型
            CreateMap<Restaurant, RestaurantViewModel>()
                .ForMember(x => x.County, y => y.MapFrom(s => s.Address.County))
                .ForMember(x => x.Province, y => y.MapFrom(s => s.Address.Province))
                .ForMember(x => x.City, y => y.MapFrom(s => s.Address.City))
                .ForMember(x => x.Street, y => y.MapFrom(s => s.Address.Street));
            #endregion
        }
    }
}
